package org.nlp2rdf.navigator.benchmark;

import org.dllearner.core.EvaluatedDescription;
import org.dllearner.utilities.experiments.Examples;
import org.nlp2rdf.navigator.client.exception.NKELearningException;
import org.nlp2rdf.navigator.component.learn.ILearn;
import org.nlp2rdf.navigator.component.learn.Learn;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.TreeSet;

/**
 * Created by Claus Stadler
 * Date: Oct 12, 2010
 * Time: 5:49:25 PM
 */
public class NkeGenericLearner
    implements IGenericLearner<String, EvaluatedDescription>
{
    private static final Logger logger = LoggerFactory.getLogger(NkeGenericLearner.class);

    private ILearn learner;

    public NkeGenericLearner(ILearn learner)
    {
        this.learner = learner;
    }

    


    private EvaluatedDescription learn(Examples example)
            throws NKELearningException
    {
        EvaluatedDescription real = learner.learnDescription(example);
        String realKBsyntax = real.getDescription().toKBSyntaxString();
        EvaluatedDescription bestDescription = learner.getLearningAlgorithm().getCurrentlyBestEvaluatedDescription();

        return bestDescription;
    }

    @Override
    public EvaluatedDescription learn(Sample<String> sample)
            throws Exception
    {
        Examples example = new Examples(
                new TreeSet<String>(sample.getPositives()),
                new TreeSet<String>(sample.getNegatives()));

        EvaluatedDescription result = null;

        result = learn(example);

        return result;
    }
}